package org.suyafei.manager.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.suyafei.enums.DomainTypeEnum;
import org.suyafei.manager.DomainManager;
import org.suyafei.mapper.DomainMapper;
import org.suyafei.model.DomainDO;

import java.util.List;

/**
 * @author 宿某人
 * @Date: 2022/01/07/5:39 下午
 * @Description:
 */
@Component
@Slf4j
public class DomainManagerImpl implements DomainManager {

    @Autowired
    private DomainMapper domainMapper;


    @Override
    public DomainDO findById(Long id, Long accountNo) {
       return domainMapper.selectOne(new QueryWrapper<DomainDO>().eq("id", id)
                .eq("account_no", accountNo));
    }

    @Override
    public DomainDO findByDomainTypeAndId(Long id, DomainTypeEnum domainTypeEnums) {
        return domainMapper.selectOne(new QueryWrapper<DomainDO>().eq("id", id)
                .eq("domain_type", domainTypeEnums.name()));
    }

    @Override
    public int addDomain(DomainDO domainDO) {
        return domainMapper.insert(domainDO);
    }

    @Override
    public List<DomainDO> listOfficialDomain() {

        return domainMapper.selectList(new QueryWrapper<DomainDO>().eq("domain_type", DomainTypeEnum.OFFICIAL.name()));
    }

    @Override
    public List<DomainDO> listCustomDomain(Long accountNo) {
        return domainMapper.selectList(new QueryWrapper<DomainDO>().eq("domain_type", DomainTypeEnum.CUSTOM.name()).eq("account_no", accountNo));

    }
}
